// pages/Video/video/video.js
var businessLogic = require('../../../utils/NetWork/Model/VideobusinessLogic.js')
var common = require('../../../utils/common.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    video: [],
    curNavId: 0,
    banjiid: 0,
    kemuid: 0,
    banbenid: 0,
    ur:'',
    tempTitle:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var orgid = common.getStorageSync("orgid")
    var userid = common.getStorageSync("userid")
    this.setData({
      orgid: orgid,
      userid: userid
    })
    this.loading()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.ConditionList = this.selectComponent("#ConditionList");
    this.ConditionList.close();
    this.loading();
    this.shanxuan();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
  , isShow: function (e) {
    this.ConditionList.isShow();
    this.loading();
  }
  , isShow2: function (e) {
    if (this.data.show == true) {
      this.setData({
        show: false,
      })
    }
  },

  detail: function (e) {
    var id = e.currentTarget.dataset.id
    var url = '../videoDetail/videoDetail?id=' + id;
    //console.log(id)
    wx.navigateTo({
      url: url,
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },
  //筛选
  shanxuan: function (ur) {
    if (ur == '' || ur == undefined) {
      var ur = '';
      let params = { "orgid": this.data.orgid, "userid": this.data.userid, "ur": ur }
      businessLogic.getCondition(params, (res) => {
        //渲染页面
        this.ConditionList.conditionList(res, ur);
      })
    } else {
      console.log(ur.detail)
      let params = { "orgid": this.data.orgid, "userid": this.data.userid, "ur": ur.detail[0] }
      businessLogic.getCondition(params, (res) => {
        //渲染页面
        this.setData({
          ur: ur.detail[0]
        })
        this.ConditionList.conditionList(res, ur.detail[0]);

      })
    }
  },
   loading: function () {
     let params = { "page": 1, "num": 1000, "orgid": this.data.orgid, "userid": this.data.userid, "ur": this.data.ur, "searchField": "title,orgid", "searchValue": this.data.tempTitle + "," + this.data.orgid }
    businessLogic.VideoList(params, (res) => {
      //console.log(res)
      for (var i = 0; i < res.length; i++) {
        if (res[i].onclick > 999999) {
          res[i].onclick = 999999 + "+";
        } else {
          res[i].onclick = res[i].onclick + "次";
        }
      }
      this.setData({
        video: res,
      });
    });
  },
  //搜索
  bindKeyInput: function (e) {
    this.setData({
      tempTitle: e.detail.value
    })
  },
  search2: function (e) {
    // console.log(tempTitle)
    let params = { "page": 1, "num": 1000, "orgid": this.data.orgid, "userid": this.data.userid, "ur":this.data.ur,"searchField": "title,orgid", "searchValue": this.data.tempTitle + "," + this.data.orgid }
    businessLogic.VideoList(params, (res) => {
      // console.log(res)
      for (var i = 0; i < res.length; i++) {
        if (res[i].onclick > 999999) {
          res[i].onclick = 999999 + "+";
        } else {
          res[i].onclick = res[i].onclick;
        }
      }
      this.setData({
        video: res,
      });
    });
  },
  // 这边要注册组件
  onReady: function () {
    //ConditionList
    this.ConditionList = this.selectComponent("#ConditionList");
  },
})